﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Collections.Specialized;

namespace OAuth.Sina
{
    public class SinaOAuthConfig : IOAuthConfig
    {
        private NameValueCollection SinaSection = (NameValueCollection)ConfigurationManager.GetSection("SinaSectionGroup/SinaSection");

        /// <summary>
        /// 得到Sina的AppKey
        /// </summary>
        /// <returns>string AppKey</returns>
        public string GetAppKey()
        {
            return SinaSection["AppKey"];
        }

        /// <summary>
        /// 得到Sina的AppSecret
        /// </summary>
        /// <returns>string AppSecret</returns>
        public string GetAppSecret()
        {
            return SinaSection["AppSecret"];
        }

        /// <summary>
        /// 得到回调地址
        /// </summary>
        /// <returns></returns>
        public Uri GetCallBackURI()
        {
            return new Uri(SinaSection["CallBackURI"]);
        }

        /// <summary>
        /// 得到请求类型
        /// GET,POST,HEADER
        /// </summary>
        /// <returns></returns>
        public OAuthEnum.RequestType GetRequestType()
        {
            string TypeString = SinaSection["RequestType"];
            OAuthEnum.RequestType Type = new OAuthEnum.RequestType();
            switch (TypeString.ToUpper())
            {
                case "GET": Type = OAuthEnum.RequestType.GET; break;
                case "POST": Type = OAuthEnum.RequestType.POST; break;
                default: Type = OAuthEnum.RequestType.GET; break;
            }
            return Type;
        }

        /// <summary>
        /// 得到OAuth认证方式
        /// </summary>
        /// <returns></returns>
        public OAuthEnum.OAuthType GetOAuthType()
        {
            string TypeString = SinaSection["OAuthType"];
            OAuthEnum.OAuthType type = new OAuthEnum.OAuthType();
            switch (TypeString.ToLower())
            {
                case "querystring": type = OAuthEnum.OAuthType.QueryString; break;
                case "httpheader": type = OAuthEnum.OAuthType.HttpHeader; break;
                default: type = OAuthEnum.OAuthType.QueryString; break;
            }
            return type;
        }
    }
}
